package com.mikelouis.test.scala.proginscala.chapter27.moduletracking

import com.mikelouis.test.scala.proginscala.chapter27.recipe.{Browser, Database, SimpleDatabase, StudentDatabase}

/**
 * Created by yuazhu on 2/25/2015.
 */
object GotApples2 {
  def main(args: Array[String]) {
    val db: Database =
      if (args(0) == "student")
        StudentDatabase
      else
        SimpleDatabase

    object browser extends Browser {
      /**
       * explicitly define browser.database is the same object as db
       */
      // .type表示database是单例类型
      // 单例类型及其特殊，只保存一个对象，在这个，是db指向的那个对象
      val database: db.type = db
    }

    /**
     * now db.FoodCategory is the same as browser.database.FoodCategory and now compile error
     */
    // browser.displayCategory(browser.database.FoodCategory)
    for (category <- db.allCategories)
      browser.displayCategory(category)

    val apple = SimpleDatabase.foodNamed("Apple").get

    for (recipe <- browser.recipesUsing(apple))
      println(recipe)
  }
}
